# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: team/gnome <pabloyoyoista@postmarketos.org>
pkgname=gnome-software
pkgver=47.1
pkgrel=0
pkgdesc="Software lets you install and update applications and system extensions"
url="https://wiki.gnome.org/Apps/Software"
arch="all"
license="GPL-2.0-or-later"
depends="gnome-app-list"
makedepends="
	appstream-dev
	flatpak-dev
	gdk-pixbuf-dev
	glib-dev
	gsettings-desktop-schemas-dev
	gtk4.0-dev
	gtk-doc
	json-glib-dev
	libadwaita-dev
	libgudev-dev
	libsoup3-dev
	libxmlb-dev
	meson
	ostree-dev
	polkit-dev
	itstool
	"
options="!check" # lots of failing tests
install="$pkgname.post-upgrade"
subpackages="
	$pkgname-dbg
	$pkgname-lang
	$pkgname-doc
	$pkgname-dev
	$pkgname-lib
	$pkgname-plugin-flatpak:flatpak_plugin
	"
source="https://download.gnome.org/sources/gnome-software/${pkgver%.*}/gnome-software-$pkgver.tar.xz
	org.gnome.software.gschema.override
	"

case "$CARCH" in
	x86|x86_64|aarch64|armv7) makedepends="$makedepends fwupd-dev" ;;
esac

build() {
	case "$CARCH" in
		x86|x86_64|aarch64|armv7) conf="-Dfwupd=true" ;;
		*) conf="-Dfwupd=false" ;;
	esac

	abuild-meson \
		-Dmalcontent=false \
		-Dpackagekit=false \
		-Dhardcoded_proprietary_webapps=false \
		-Dtests=false \
		-Dexternal_appstream=true \
		$conf \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	install -Dm644 "$srcdir"/org.gnome.software.gschema.override \
		-t "$pkgdir"/usr/share/glib-2.0/schemas/
}

dev() {
	default_dev

	amove usr/lib/gnome-software/libgnomesoftware.so
}

lib() {
	pkgdesc="$pkgdesc (shared library)"
	depends=""

	amove usr/lib/gnome-software/libgnomesoftware.so.*
}

flatpak_plugin() {
	pkgdesc="$pkgdesc (flatpak plugin)"
	install_if="$pkgname=$pkgver-r$pkgrel flatpak"
	depends=""

	amove usr/lib/gnome-software/plugins-21/libgs_plugin_flatpak.so
	amove usr/share/metainfo/org.gnome.Software.Plugin.Flatpak.metainfo.xml
}
sha512sums="
18c500ef0487f9303097f939e11d2841df87d609d05484e3d4419ce9a27f6156ec4aabeca61191724d557b5603ff7857095ed09fc065b6064d0b92286bc19748  gnome-software-47.1.tar.xz
fa82dfdaaa89554ae0882be6ed25ebcb48e7c9120c645401f369d1f888712002b2627900f629515136d66cf05dcb7d3a09d2bfd775c8063d3ec2d39c64cb1a5b  org.gnome.software.gschema.override
"
